package org.orion.engine;

import javax.media.opengl.GL;

import org.orion.engine.math.Vector3d;
import org.orion.engine.math.Vector4i;


public class Camera {
	
	public static final double fovy = 60.0;//45.0;
	public static final double near = 0.1;
	public static final double far = 1000.0;
	
	private Vector4i viewport;
	
	public Vector3d position = new Vector3d();
	public Vector3d center = new Vector3d();
	public Vector3d up = new Vector3d();

	
	public Camera()
	{
		initZero();
	}
	
	public Camera(Vector4i viewport)
	{
		initZero();
		this.viewport = viewport;
		
    }
	
	public Camera(Vector3d position)
	{
		initZero();
		this.position = position;
	}
	
	public Camera(Vector4i viewport,Vector3d position)
	{
		initZero();
		this.position = position;
		this.viewport = viewport;
		//changeCenterUp();
		
    }

	private void initZero(){
		position = new Vector3d(0.0, 0.0, -1.0);
		center = new Vector3d(0.0, 0.0, 0.0);
		up = new Vector3d( 0.0, 1.0, 0.0);
		viewport = new Vector4i(0,0,100,100);
	}
	
	public void glViewport(){
		GLStatic.gl.glViewport( viewport.x, viewport.y, viewport.z, viewport.w);
	}
	
	public void glModelView() {
		GLStatic.gl.glMatrixMode(GL.GL_MODELVIEW);
		GLStatic.gl.glLoadIdentity();
		GLStatic.glu.gluLookAt(
			position.x,position.y,position.z,
			center.x,center.y,center.z,
			up.x,up.y,up.z);
	}
	
	public void glProjection() {
		GLStatic.gl.glMatrixMode(GL.GL_PROJECTION);
		GLStatic.gl.glLoadIdentity();
	    GLStatic.glu.gluPerspective(fovy, (double)viewport.z/viewport.w, near, far);
	}
	
	public Vector4i getViewport() {
		return viewport;
	}

	public void setViewport(Vector4i viewPort) {
		this.viewport = viewPort;
	}
}
